// Simulation of a forked bolt of lightning -- Bob Covey

ConB=1,



Aspc=0,

/*
Construction:
    Start with a standard waveshape oriented top-to-botom:
	X = .2*mag(s)
	Y = 1-2*s
    Change the basic shape from a straight line to more of an S curve
	X += .3 * sin (5*s+t)
    Allow the start of the stroke to move around a bit:
	X += .1 * sin (.5*t)
    Cause the bottom to "whip" back and forth while holding the top:
	X += s*0.2*(cos(3*t)+sin(5*t))
    This makes the primary stroke:
*/

B0=".25 * t",   // Allow time scaling

C0=".2 * mag(s) +
    .3 * sin (5*s+B0) +
    .1 * sin (.5*B0) +
    s * 0.2 * (cos(3*B0)+sin(5*B0))",
C1="1 - 2*s",

X0="c0",
Y0="c1",

/*
    To make a branch, we note that the function "clip(s-branch)" is
    zero while "s" is less than "branch", then evenly increases.  If we
    make a second waveform equal to the first plus this function
    (suitably scaled), it will follow the first and then branch off at
    the appropriate point.  This can be repeated to have multiple forks,
    or forks off forks...

    For the first branch below, we set
	branch = .5+.06*sin(t)
    so that the breakaway point moves a bit, and scale by
	(sin(t)+.4*cos(9*s))
    which causes the fork to have a different shape after it separates.
*/

C2="clip(s - .5+.06*sin(B0)) * (sin(B0)+.4*cos(9*s))",
X1="c0 + c2",
Y1="c1",

// Second fork is small, so branch & scaling factor can be simpler:
X2="c0 + clip(s - .9) * 1.5 * sin(1.5*B0)",
Y2="c1",

// Last one is a fork off the first fork:
X3="c0 + c2 - clip(s - .7+.05*cos(1.2*B0)) *
               .6 *(cos(1.2*B0)+.3*sin(12*s))",
Y3="c1",


// stroke gets thinner as it divides...
LWdt="5 * (1-s)^.7",

Vers=100
